package com.lishe.lishe.lishe.module.mall.adapter;


import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lishe.lishe.Imageloader.ImageLoaderUtils;
import com.lishe.lishe.R;
import com.lishe.lishe.lishe.MyRecyclerView.RecyclerviewBaseAdapter;
import com.lishe.lishe.lishe.module.mall.bean.category.CategoryFirst;

import java.util.List;

/**
 * Created by yang on 2017/11/6.
 */

public class ClassificationItemAdapter extends RecyclerviewBaseAdapter {
    private Activity mContext;
    private List<CategoryFirst> mList;

    public ClassificationItemAdapter(Activity context, List<CategoryFirst> list){
        this.mContext=context;
        this.mList=list;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolderMy(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(mContext).inflate(R.layout.item_smallclass,null);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolderMy(RecyclerView.ViewHolder holder, int position) {
        CategoryFirst category = mList.get(position);
        MyViewHolder viewHolder = (MyViewHolder) holder;
        viewHolder.text.setText(category.getCate_name());
        ImageLoaderUtils.displayImage(mContext, category.getImg_url(), viewHolder.img, R.drawable.defalut_img);

        if (position % 3 == 0) {//左
            viewHolder.left.setVisibility(View.GONE);
            viewHolder.right.setVisibility(View.VISIBLE);
        } else if (position % 3 == 1) {//中
            viewHolder.left.setVisibility(View.VISIBLE);
            viewHolder.right.setVisibility(View.VISIBLE);
        } else if (position % 3 == 2){//右
            viewHolder.left.setVisibility(View.VISIBLE);
            viewHolder.right.setVisibility(View.GONE);
        }
    }

    @Override
    public int getItemCountMy() {
        return mList.size();
    }

    @Override
    public int getItemViewTypeMy(int position) {
        return 0;
    }

    public class MyViewHolder extends RecyclerView.ViewHolder{
        ImageView img;
        TextView text;
        View left, right;

        public MyViewHolder(View itemView) {
            super(itemView);
            img = itemView.findViewById(R.id.img);
            text = itemView.findViewById(R.id.text);
            left = itemView.findViewById(R.id.left);
            right = itemView.findViewById(R.id.right);
        }
    }

}